import java.util.ArrayList;
import java.util.List;

//二叉树的后序遍历---用栈
class Solution1 {
    class TreeNode{
        int val;
        TreeNode left;
        TreeNode right;

        public TreeNode(int val) {
            this.val = val;
        }
    }
    public List<Integer> postorderTraversal(TreeNode root) {
        List<Integer>list=new ArrayList<>();
        if(root==null){
            return list;
        }
        postOrder(root,list);
        return list;

    }
    public  void postOrder(TreeNode root,List<Integer>list){
        if(root==null){
            return;
        }
        postOrder(root.left,list);
        postOrder(root.right,list);
        list.add(root.val);
    }
}